package com.bz.portal.service.impl;

import com.bz.portal.feign.CommonContentFeignClient;
import com.bz.portal.feign.CommonRedisFeignClient;
import com.bz.portal.service.ContentService;
import com.bz.utils.Result;
import com.bz.vo.ContentVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class ContentServiceImpl implements ContentService {

    @Autowired
    private CommonContentFeignClient commonContentFeignClient;
    @Autowired
    private CommonRedisFeignClient commonRedisFeignClient;

    /**
     * 查询首页大广告位
     * @return
     */
    @Override
    public Result selectFrontendContentByAD() {
        List<ContentVo> contentVoList;
        try {
            contentVoList = commonRedisFeignClient.selectContentAD();
            if (contentVoList != null){
                return Result.ok(contentVoList);
            }
        } catch (Exception e) {
            log.error("【查询首页大屏广告缓存失败】.{}",e);
        }
        contentVoList = commonContentFeignClient.selectFrontendContentByAD();
        if (contentVoList != null){
            commonRedisFeignClient.insertContentAD(contentVoList);
        }
        return Result.ok(contentVoList);
    }
}
